package com.xh.audit.service.impl;


import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.xh.audit.entity.project.ProjectArchive;
import com.xh.audit.entity.project.table.ProjectArchiveTableDef;
import com.xh.audit.mapper.ProjectArchiveMapper;
import com.xh.audit.service.ProjectArchiveService;
import com.xh.common.R;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 项目档案表;项目归档/项目档案
 * 流程的关联到审计文书 ;
 * 档案的再关联文书;
 * 档案中关联的文书不让删,自上传的可以删;
 * 服务实现类
 * </p>
 *
 * @author lhl
 * @since 2023-10-19
 */
@Service
public class ProjectArchiveServiceImp extends ServiceImpl<ProjectArchiveMapper, ProjectArchive> implements ProjectArchiveService {

    /**
     * 档案中关联的文书不让删,自上传的可以删;
     *
     * @param ids
     * @return
     */
    @Override
    public R<ProjectArchive> del(List<Integer> ids) {
        //验证上送的是否包含关联的文书
        QueryWrapper queryWrapper = QueryWrapper.create()
                .and(ProjectArchiveTableDef.PROJECT_ARCHIVE.ID.in(ids))
                //是否审计文书,1是0否
                .and(ProjectArchiveTableDef.PROJECT_ARCHIVE.AUDIT_DOCUMENT_FLAG.eq(1));
        long count = this.count(queryWrapper);
        if (count > 0) {
            R.failed("删除验证不通过,不能删除审计文书档案");
        }
        
        this.removeByIds(ids);
        return R.success("删除成功");
    }
}
